package com.ellecity06.cwhiskymall.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.common.ktx.loadGif
import com.ellecity06.common.ktx.toAmount
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.TagItem
import com.ellecity06.cwhiskymall.bean.response.LiveRoomGoodResponse
import com.ellecity06.cwhiskymall.databinding.ItemLiveGoodBinding
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent

/**
 * @author ellecity06
 * @time 2025/1/13 11:43
 * @des
 */
class LiveGoodAdapter : BaseAdapter<LiveRoomGoodResponse, ItemLiveGoodBinding>() {
    private val tagList: List<TagItem> by lazy {
        mutableListOf(
            TagItem("大牌好物"),
            TagItem("正品保障")
        )
    }

    override fun inflateBinding(layoutInflater: LayoutInflater, parent: ViewGroup, viewType: Int): ItemLiveGoodBinding {
        return ItemLiveGoodBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(binding: ItemLiveGoodBinding, position: Int, item: LiveRoomGoodResponse) {
        binding.ivGoodImg.load(context, item.mainProductImage)
        binding.tvGoodsName.text = item.productName
        binding.tvPrice.text = "￥${item.marketPrice}"
        binding.tvNum.text = "${position + 1}"
        binding.layoutTop.visibility = if (item.explanationStatus==1) View.VISIBLE else View.GONE
        if (item.explanationStatus==1){
            binding.ivPlaying.loadGif(context, R.drawable.gif_live_playing)
        }else{
            binding.ivPlaying.setImageResource(R.mipmap.placeholder_good)
        }
        binding.tvContribution.text = "赠送${item.contribution.toAmount()}贡献金"
//        setTagData(binding.rvTag)
    }


    private fun setTagData(rvTag: RecyclerView) {
        val layoutManager = FlexboxLayoutManager(context)
        layoutManager.flexDirection = FlexDirection.ROW
        layoutManager.justifyContent = JustifyContent.FLEX_START
        rvTag.layoutManager = layoutManager
        val goodTagAdapter = GoodTagAdapter()
        rvTag.adapter = goodTagAdapter
        goodTagAdapter.submitList(tagList)
    }
}